-----------------
--LINE OF SIGHT--
-----------------

if not LineOfSightFrame then
	LineOfSightFrame = CreateFrame("FRAME", nil, UIParent)
	LineOfSightFrame:Hide()
end

if not LineOfSightTable then
	LineOfSightTable = {}
else
	for i = 1, #LineOfSightTable do
		local time = LineOfSightTable[i].time
		local val = PQI_Fury_LineofSightTime_value or 2
		if time
				and GetTime() > time + val then
			local unit = LineOfSightTable[i].unit
			tremove(LineOfSightTable, i)
		end
	end
end

function LineOfSight_OnEvent(self, event, arg1)
	if event == "UI_ERROR_MESSAGE" then
		if arg1 == SPELL_FAILED_LINE_OF_SIGHT then
			local unit = GHOST_CastTarget
					or "Unknown"
			if not UnitIsUnit("player", unit) then
				tinsert(LineOfSightTable, 1, { unit = unit, time = GetTime() })
			end
		end
	end
end

LineOfSightFrame:SetScript("OnEvent", LineOfSight_OnEvent)
LineOfSightFrame:RegisterEvent("UI_ERROR_MESSAGE")

function LineOfSight(unit)
	for i = 1, #LineOfSightTable do
		if unit == LineOfSightTable[i].unit then
			return true
		end
	end
end